package com.x.client.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.gg.image.config.GlideApp
import com.gg.utils.isNullOrZero
import com.x.client.App
import com.x.client.R
import com.x.client.bean.Car

/**
 * Creator : GG
 * Date    : 2018/5/23
 * Mail    : gg.jin.yu@gmai.com
 * Explain :
 */
class CarListAdapter : BaseQuickAdapter<Car, BaseViewHolder>(R.layout.item_car, listOf()) {

    override fun convert(helper: BaseViewHolder, item: Car) {
        val imageView = helper.getView<ImageView>(R.id.car_photo)
        GlideApp.with(mContext).load(App.instance.getImageUrl() + item.carImageUrl + ".r_400xh_300").error(R.drawable.item_car_placeholder).placeholder(R.drawable.item_car_placeholder).centerCrop().into(imageView)
        val subtitle = item.getMileageStr() + (if (item.getMileageStr().isNullOrBlank()) "" else "/") + item.getTime()
        helper.setText(R.id.car_title, item.carTitle)
                .setVisible(R.id.authentication, item.carAuthState == Car.CarAuthState_Verified)
                .setText(R.id.carSubtitle, subtitle)
                .setText(R.id.carSaleTime, item.getCarLicenceDate())
                .setText(R.id.carPrice, item.carRetailPrice.toString())
                .setVisible(R.id.carPriceLL, !item.carRetailPrice.isNullOrZero())
                .setVisible(R.id.negotiable, item.carRetailPrice.isNullOrZero())


    }
}